﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace GameBasic
{
    public static class EnumComparer<T> where T : unmanaged, Enum
    {
        class Comparer32 : IEqualityComparer<T>
        {
            public bool Equals(T x, T y)
            {
                return ExtEnum.Compare32(x, y);
            }

            public int GetHashCode(T obj)
            {
                unsafe
                {
                    int v0 = 0;
                    *(T*)&v0 = obj;
                    return v0;
                }
            }
        }

        class Comparer64 : IEqualityComparer<T>
        {
            public bool Equals(T x, T y)
            {
                return ExtEnum.Compare(x, y);
            }

            public int GetHashCode(T obj)
            {
                unsafe
                {
                    ulong v0 = 0;
                    *(T*)&v0 = obj;
                    return (int)((v0 >> 32) ^ v0);
                }
            }
        }

        public static IEqualityComparer<T> Int32 => new Comparer32();

        public static IEqualityComparer<T> Int64 => new Comparer64();
    }
}